﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace WoWAPI
{
	public class Realm
	{
		private const string REALM_URL = "http://{0}.battle.net/api/wow/realm/status";

		public string Type { get; set; }
		public bool Queue { get; set; }
		public bool Status { get; set; }
		public string Population { get; set; }
		public string Name { get; set; }
		public string Slug { get; set; }
		public string Region { get; set; }

		public Realm() { }

		public static Realm GetRealm(string RealmName, string Region)
		{
			return GetRealms(new string[] { RealmName }, Region)[0];
		}

		public static Realm[] GetRealms(string[] RealmNames, string Region)
		{
			string url = string.Format(REALM_URL, Region);

			if (RealmNames.Length > 0)
				url += "?realms=" + String.Join(",", RealmNames);

			Realm[] realms = API.DeserializeJSON<RealmCollection>(API.MakeWebRequest(url)).Realms; 

			return realms;
		}

		public static Realm[] GetAllRealms(string Region)
		{
			return GetRealms(new string[] { }, Region);
		}

		private class RealmCollection
		{
			public Realm[] Realms { get; set; }

			public RealmCollection() { }
		}
	}
}
